package com.service.impl;

import com.dao.ints.FlightMapper;
import com.dao.ints.OrderTicketMapper;
import com.dao.ints.UserInfoMapper;
import com.entity.Flight;
import com.entity.OrderTicket;
import com.entity.UserInfo;
import com.service.cairns;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
public class cairo  implements cairns {


    private FlightMapper flightMapper;
    @Autowired
    public void setFlightMapper(FlightMapper flightMapper) {
        this.flightMapper = flightMapper;
    }

    private UserInfoMapper userInfoMapper;
  @Autowired
   public void setUserInfoMapper(UserInfoMapper userInfoMapper) {
        this.userInfoMapper = userInfoMapper;
    }

    private OrderTicketMapper orderTicketMapper;
    @Autowired
    public void setOrderTicketMapper(OrderTicketMapper orderTicketMapper) {
        this.orderTicketMapper = orderTicketMapper;
    }

    public  void  zhuce(UserInfo userInfo){
        userInfoMapper.saveUser(userInfo);
    }

    public List<OrderTicket> self(String uses){
             List<OrderTicket>    list  =  orderTicketMapper.listOrderTicket2(uses);
              return  list;
    }
    public  void  booking(OrderTicket orderTicket){
        orderTicketMapper.saveOrderTicket(orderTicket);
         Integer aa =orderTicket.getFlights();
         flightMapper.updateFlight(aa);
    }

    public  void  refund(Integer flights){
        orderTicketMapper.delOrderTicket(flights);
        flightMapper.zenaFlight(flights);
    }

    public  void  addzenjia(Flight flight){
      flightMapper.saveFlight(flight);
    }

    public  void updateFlight(Flight flight){
        flightMapper.underweight(flight);
    }

    public  void deleteFlight(Integer flight){
         flightMapper.delFlight(flight);
    }



    public void  updater(UserInfo userInfo){
        Object ss = SecurityUtils.getSubject().getPrincipal();
        String aa =  String.valueOf(ss);
        String bb = userInfo.getLoginPassword();
        String cc = userInfo.getLoginName();
        UserInfo gg = userInfoMapper.getUser(aa);
        String  hh = gg.getLoginPassword();//数据库密码
        Md5Hash hash1 = new Md5Hash(cc, aa, 2);//原密码
        Md5Hash hash = new Md5Hash(bb, aa, 2);//新密码
        String dd=hash1.toString();
        String  ff = hash.toString();
        userInfo.setLoginPassword(ff);
        userInfo.setLoginName(aa);
        userInfoMapper.updater(userInfo);
        }






    }



